***********************
*  Format and Analyze *
*     10th Circuit.   *
***********************


clear all
 
*use "/Users/damoncann/Box/Argument Data/deidentifieddata.dta"
use "/Users/DamonLaptop/Dropbox/Argument/Data/deidentifieddata.dta"
*use "/Users/goelzhauser/Dropbox/Research/Argument/Data/deidentifieddata.dta"

*Label Variables

label variable q1removed "Legit: Judges...who make decisions at odds...should be removed"
label variable q3mixpol "Legit: The federal courts get too mixed up in politics"
label variable q2doaway "Legit ...do away with the federal courts altogether"
label variable q4jurisdic "Legit: The right of the federal courts to decide...controversial...should be reduced"
label variable q6_1realismslide "Realism Slider (100=Legal, 0=Attitudinal)"
label variable q7priordecis "Gibson: A federal Court's prior decisions play an important role in judicial decision making"
label variable q8lawandconst "Gibson: Judges..say..decisions..based on..law..but..judges are really basing..on personal beliefs"
label variable q9valuesviews "Judges values have little to do with how they decide..."
label variable q10noparty "Judges party affiliations have little to do with how they decide..."
label variable q12klifeterm "Knowledge: life term"
label variable q13kjudrev "Knowledge: Judicial Review"
label variable q14_1kabort "Knowledge: Court Decided Abortion"
label variable q14_2kblackrights "Knowledge: Court Decided Rights of Black Americans"
label variable q14_3kmaxrate "Knowledge: Court Decided Maximum Income tax rate"
label variable q30lawyerconf "How much confidence you, yourself have in lawyers"
label variable q32lawyerhonest "Please tell me how you would rate the honesty and ethical standards of lawyers"
label variable q33_1lawyerwellbeing "Likert: Lawyers contribute alot to society's well-being"
label variable q33_2courtcamera "Likert: Courts should allow television cameras into their courtrooms when they hear arguments.."
label variable q15courtparticipate "Court Experience"
label variable q16race "Race"
label variable q17pid "Party ID: Party Identification 3 point"
label variable q18pidstrong "Party ID: Weak or Strong Party Identifier"
label variable q19pidlean "Party ID: Partisan leanings of independents"
label variable q23lawschool "How likely are you to attend law school?"
label variable q20gender "What is your gender?"
label variable q22major "What is your major?"
label variable q24classstanding "What is your class standing"
label variable q24_6_text "Class Standing Other/Free response"

encode session, gen(sessionID)


*Recode to a consistent scale

*Legitimacy variables: Higher values equal more pro-legitimacy responses

label define likert5 1 "Strongly Agree" 2 "Somewhat Agree"  3 "Neither" 4 "Somewhat Disagree" 5 "Strongly Disagree"

label values q1removed q3mixpol q2doaway q4jurisdic likert5

factor q1removed q3mixpol q2doaway q4jurisdic, pcf
predict legit
label variable legit "Legitimacy Index (Principal Components)"

****Experient with Polychoric
polychoric q1removed q3mixpol q2doaway q4jurisdic
global N = r(sum_w)

matrix r = r(R)
factormat r, n($N) pcf
predict polylegit

corr polylegit legit

****End Experiment with Polychoric

label define liker5rev 1 "Strongly Disagree" 2 "Somewhat Disagree" 3 "Neither" 4 "Somewhat Agree" 5 "Strongly Agree"

recode q7priordecis (1=5) (2=4) (3=3) (4=2) (5=1)
recode q9valuesviews (1=5) (2=4) (3=3) (4=2) (5=1)
recode q10noparty (1=5) (2=4) (3=3) (4=2) (5=1)

label values q7priordecis q9valuesviews q10noparty   liker5rev
label values q8lawandconst   likert5

factor  q7priordecis q8lawandconst q9valuesviews q10noparty, pcf
predict gibsonlegal

**Another polychoric experiment

polychoric q7priordecis q8lawandconst q9valuesviews q10noparty
global N2 = r(sum_w)

matrix r = r(R)
factormat r, n($N2) pcf
predict polygibsleg

corr polygibsleg gibsonlegal



************ 
* Analysis *
************

*Legitimacy

ttest legit, by(treatcntrl) 

*Normalize to [0,1] 

generate normLegit = legit 
sum normLegit, meanonly
replace normLegit = (normLegit - `r(min)') / (`r(max)'-`r(min)')

sum normLegit
ttest normLegit, by(treatcntrl) 

*Plot 

stripplot normLegit, over(treatcntrl) ///
	cumul cumprob bar vertical boffset(0) height(.5) ///
	bar(lcolor(black) mean(mcolor(black) ms(O))) ///
	ytitle(Judicial Legitimacy, margin(medium) size(4)) ///
	xtitle("")

*Gibson and Caldeira (2011) Realism-Legalism

sum gibsonlegal
ttest  gibsonlegal, by(treatcntrl)
	
*Normalize to [0,1] 

generate normLegal = gibsonlegal 
sum normLegal, meanonly
replace normLegal = (normLegal - `r(min)') / (`r(max)'-`r(min)')

sum normLegal
ttest normLegal, by(treatcntrl) 

*Plot;

stripplot normLegal, over(treatcntrl) ///
	cumul cumprob bar vertical boffset(0) height(.5) ///
	bar(lcolor(black) mean(mcolor(black) ms(O))) ///
	ytitle(Law Motivates Judicial Decisions, margin(medium) size(4)) ///
	xtitle("")

	
*Gibson Realism/Legalism
sum gibsonlegal
ttest  gibsonlegal, by(treatcntrl)

gen treatment = 0
replace treatment = 1 if treatcntrl=="Treatment"
oprobit q7priordecis treatment
oprobit q8lawandconst treatment
oprobit q9valuesviews treatment
oprobit q10noparty treatment


*Lawyers (No effect)

alpha q30lawyerconf q32lawyerhonest q33_1lawyerwellbeing
factor q30lawyerconf q32lawyerhonest q33_1lawyerwellbeing, pcf
predict lawyers
ttest  lawyers, by(treatcntrl)
oprobit q30lawyerconf treatment
oprobit q32lawyerhonest treatment
oprobit q33_1lawyerwellbeing treatment

*Cameras in Courtroom (No effect)

oprobit q33_2courtcamera treatment

*Law School Attendance (No effect)

oprobit q23lawschool treatment

*Court Knowledge
recode q12klifeterm (2=1) (else=0), gen(cor_term)
recode q13kjudrev (1=1) (else=0), gen(cor_judrev)
recode q14_1kabort (1=1) (else=0), gen(cor_abort)
recode q14_2kblackrights (1=1) (else=0), gen(cor_blackrights)
recode q14_3kmaxrate (2=1) (else=0), gen(cor_maxrate)

gen knumcorrect = cor_term + cor_judrev + cor_abort + cor_blackrights + cor_maxrate

ttest knumcorrect, by(treatcntrl)

tab  cor_term treatcntrl, col chi2
tab  cor_judrev treatcntrl, col chi2
tab  cor_abort treatcntrl, col chi2
tab  cor_blackrights treatcntrl, col chi2
tab  cor_maxrate treatcntrl, col chi2

*******************
* Balance Testing *
*******************

*Party ID: Balance is good.
*Note: 1=Strong Dem 2=Weak Dem 3=Lean Dem 4=Independent 5=lean Rep 6=Weak Rep 7=Strong Rep
gen pid7 = .
replace pid7=1 if q17pid==1 & q18pidstrong==1
replace pid7=2 if q17pid==1 & q18pidstrong==2
replace pid7=3 if q17pid==3 & q19pidlean==2
replace pid7=4 if q17pid==3 & q19pidlean==3
replace pid7=5 if q17pid==3 & q19pidlean==1
replace pid7=6 if q17pid==2 & q18pidstrong==2
replace pid7=7 if q17pid==2 & q18pidstrong==1

recode pid7 (1/3=1) (4=2) (5/7=3), gen(pid3)
label variable pid7 "7 category Party ID"
label variable pid3 "3 category Party ID, Leaners as Partisans"


tab treatcntrl pid7, col chi2
tab treatcntrl pid3, col chi2

*Intra-Session Party ID Balance
tab treatcntrl pid7 if sessionID==1, col chi2
tab treatcntrl pid3 if sessionID==1, col chi2

tab treatcntrl pid7 if sessionID==2, col chi2
tab treatcntrl pid3 if sessionID==2, col chi2


*Gender: Balance is good
tab  treatcntrl q20gender, col chi2

tab  treatcntrl q20gender if sessionID==1, col chi2
tab  treatcntrl q20gender if sessionID==2, col chi2

*Class Standing: Balance is good

tab treatcntrl q24classstanding, col chi2

*Court Experience : Messy, but OK.

tab treatcntrl q15courtparticipate, col chi2

gen courtexp = 1
replace courtexp = 0 if q15courtparticipate == "7"

tab treatcntrl courtexp, col chi2

tab treatcntrl courtexp if sessionID==1, col chi2
tab treatcntrl courtexp if sessionID==2, col chi2

*Court Experience: Jury Only, balance is good and interpretable
gen jury = 0 if q15courtpart ~=""
replace jury =1 if   q15courtpart =="1" | q15courtpart =="1,2" | q15courtpart =="1,3" | q15courtpart =="1,3,5" | q15courtpart =="1,5" | q15courtpart =="1,5,6" | q15courtpart =="1,6" | q15courtpart =="2,6" 
 tab treatcntrl jury, col chi2
  tab treatcntrl jury if sessionID==1, col chi2
 tab treatcntrl jury if sessionID==2, col chi2

*Race: Balance OK.

tab treatcntrl q15courtparticipate, col chi2

gen white = 0
replace white = 1 if q16race=="1"

tab treatcntrl white, col chi2

tab treatcntrl white if sessionID==1, col chi2
tab treatcntrl white if sessionID==2, col chi2




stop;
*********************
*    Robustness     *
*********************

*Realism Slider
sum q6_1realismslide
ttest q6_1realismslide, by(treatcntrl) 

stripplot q6_1realismslide, over(treatcntrl) ///
	cumul cumprob bar vertical boffset(0) height(.5) ///
	bar(lcolor(black) mean(mcolor(black) ms(O))) ///
	ytitle(Law Motivates Judicial Decisions, margin(medium) size(4)) ///
	xtitle("") 
	
*Results by Session

gen earlysession = 0
replace earlysession = 1 if session=="Early (8:40)"

gen treatXearly = treatment*earlysession

**Legitimacy

sum normLegit if earlysession==1
ttest normLegit if earlysession==1, by(treatcntrl)  

stripplot normLegit if earlysession==1, over(treatcntrl) ///
	cumul cumprob bar vertical boffset(0) height(.5) ///
	bar(lcolor(black) mean(mcolor(black) ms(O))) ///
	ytitle(Judicial Legitimacy, margin(medium) size(4)) ///
	xtitle("") ///
	name(legit1, replace)

sum normLegit if earlysession==0
ttest normLegit if earlysession==0, by(treatcntrl) 

stripplot normLegit if earlysession==0, over(treatcntrl) ///
	cumul cumprob bar vertical boffset(0) height(.5) ///
	bar(lcolor(black) mean(mcolor(black) ms(O))) ///
	ytitle(Judicial Legitimacy, margin(medium) size(4)) ///
	xtitle("") ///
	name(legit2, replace)

graph combine legit1 legit2, ycommon 

reg normLegit treatment earlysession treatXearly

estimates store legitBySession

coefplot (legitBySession, msymbol(O) mcolor(black) ciopts(lcolor(black))), ///
drop(_cons) ///
title("") ///
coeflabels(treatment = "Treatment" earlysession = "First Session" treatXearly = "Treatment x First Session") ///
xline(0, lpattern(dot)) ///
grid(none)


reg normLegit treatment earlysession treatXearly
margins, at(treatment=1 earlysession=1 treatXearly=1) ///
		 at(treatment=1 earlysession=0 treatXearly=0) post

		 test _b[1._at] = _b[2._at]

**Law/Ideology

sum normLegal if earlysession==1
ttest normLegal if earlysession==1, by(treatcntrl)  

stripplot normLegal if earlysession==1, over(treatcntrl) ///
	cumul cumprob bar vertical boffset(0) height(.5) ///
	bar(lcolor(black) mean(mcolor(black) ms(O))) ///
	ytitle(Law Motivates Judicial Decisions, margin(medium) size(4)) ///
	xtitle("") ///
	name(legal1, replace)

sum normLegal if earlysession==0
ttest normLegal if earlysession==0, by(treatcntrl) 

stripplot normLegal if earlysession==0, over(treatcntrl) ///
	cumul cumprob bar vertical boffset(0) height(.5) ///
	bar(lcolor(black) mean(mcolor(black) ms(O))) ///
	ytitle(Law Motivates Judicial Decisions, margin(medium) size(4)) ///
	xtitle("") ///
	name(legal2, replace)

graph combine legal1 legal2, ycommon 

reg normLegal treatment earlysession treatXearly

estimates store lawBySession

coefplot (lawBySession, msymbol(O) mcolor(black) ciopts(lcolor(black))), ///
drop(_cons) ///
title("") ///
coeflabels(treatment = "Treatment" earlysession = "First Session" treatXearly = "Treatment x First Session") ///
xline(0, lpattern(dot)) ///
grid(none)

reg normLegal treatment earlysession treatXearly
margins, at(treatment=1 earlysession=1 treatXearly=1) ///
		 at(treatment=1 earlysession=0 treatXearly=0) post

		 test _b[1._at] = _b[2._at]
		 


*No differential effects for lawyers 
ttest  lawyers if earlysession==1, by(treatcntrl)
ttest  lawyers if earlysession==0, by(treatcntrl)
regress lawyers treatment earlysession treatXearly

*No differential effects for Court Cameras
oprobit q33_2courtcamera treatment earlysession treatXearly

*No differential effects for law school, though more law school interest in the afternoon than morning
oprobit q23lawschool treatment earlysession treatXearly

*Realism Slider
sum q6_1realismslide
ttest q6_1realismslide, by(treatcntrl) 

stripplot q6_1realismslide, over(treatcntrl) ///
	cumul cumprob bar vertical boffset(0) height(.5) ///
	bar(lcolor(black) mean(mcolor(black) ms(O))) ///
	ytitle(Law Drives Decisions, margin(medium) size(4)) ///
	xtitle("")




